package com.geekband.Test01;

import android.app.Activity;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;

/**
 * Function:
 * Create date on 15/11/25.
 *
 * @author Conquer
 * @version 1.0
 */
public class SendBroadcastActivity extends Activity {

    public static final String COM_GEEKBAND_TEST_BROADCAST = "com.geekband.test.broadcast";
    private TestBroadcastReceiver mTestBroadcastReceiver = new TestBroadcastReceiver();
    private Button mSendBroadcastButton;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        setContentView(R.layout.activity_test_broadcast);


        mSendBroadcastButton = (Button) findViewById(R.id.send_broadcast_button);

        mSendBroadcastButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                // 发送广播
                Intent intent = new Intent();
                intent.setAction(COM_GEEKBAND_TEST_BROADCAST);
                intent.putExtra("toast", "this is my toast of broadcast");

                sendBroadcast(intent);
            }
        });



    }

    @Override
    protected void onStart() {
        super.onStart();
        // 有一个intentFilter  动态注册广播
        IntentFilter intentFilter = new IntentFilter();
        intentFilter.addAction(COM_GEEKBAND_TEST_BROADCAST);
        registerReceiver(mTestBroadcastReceiver,intentFilter);
    }

    @Override
    protected void onStop() {
        super.onStop();
        unregisterReceiver(mTestBroadcastReceiver);
    }
}
